package export;

import java.util.HashMap;
import java.util.Map;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;

/**
 * Export request contain all needed information to export a report. It don't contain any specific definition for
 * report.
 * 
 */
public class ExportRequest extends AbstractRequest<ExportRequest> {
    private static final long serialVersionUID = 4954996833027569958L;
    private String basePath;
    private String fileName;
    private Map<String, Object> parameters = new HashMap<String, Object>();
    private ExportType type = ExportType.XLS;
    private boolean isWordWrap;
    private boolean isUseTimeStamp = false;

    /**
     * This map is used to define parameter use in report and another property like font, color...
     * 
     * @param additionProperties
     */
    public void putAdditionProperties(String property, Object value) {
        additionalProperties.put(property, value);
    }

    /**
     * Get current basePath used for report.
     * 
     * @return basePath.
     */
    public String getBasePath() {
        return basePath;
    }

    /**
     * <p>
     * Local base path of report file
     * </p>
     * <p>
     * Example: D:/report/file
     * </p>
     * <ul>
     * <li>D:/report/file - > legal</li>
     * <li>D:\report\file - > legal</li>
     * <li>D:/report/file/ - > illegal</li>
     * </ul>
     * 
     * @param basePath
     */
    public void setBasePath(String basePath) {
        this.basePath = basePath;
    }

    /**
     * Get current report file name. It must contain only report file name.
     * 
     * @return report file name.
     */
    public String getFileName() {
        return fileName;
    }

    /**
     * Set current report file name.
     * 
     * @param fileName
     */
    public void setFileName(String fileName) {
        this.fileName = fileName;
    }

    /**
     * Set export type for report.
     * 
     * @param type
     */
    public void setType(ExportType type) {
        this.type = type;
    }

    /**
     * Get current export type is used in request. Default is PDF.
     * 
     * @return
     */
    public ExportType getType() {
        return type;
    }

    /**
     * Set enable or disable word wrap in report.
     * 
     * @param isWordWrap
     */
    public void setWordWrap(boolean value) {
        this.isWordWrap = value;
    }

    /**
     * Return value of <code>isWordWrap</code> property.
     * 
     * @return true if word wrap is enable, otherwise false.
     */
    public boolean isWordWrap() {
        return isWordWrap;
    }

    /**
     * Add a parameter value into request.
     * 
     * @param key
     * @param value
     */
    public void addParameter(String key, Object value) {
        parameters.put(key, value);
    }

    /**
     * Get current value of <code>parameters</code> property.
     * 
     * @return Map&lt;String, Object&gt;
     */
    public Map<String, Object> getParameters() {
        return parameters;
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
    }

    /**
     * Set new value for <code>isUseTimeStamp</code> property.
     */
    public void setUseTimeStamp(boolean useTimeStamp) {
        this.isUseTimeStamp = useTimeStamp;
    }

    /**
     * Get current value of <code>isUseTimeStamp</code> property.
     * 
     * @return isUseTimeStamp;
     */
    public boolean isUseTimeStamp() {
        return isUseTimeStamp;
    }
}
